package org.cainiaojin.controller;

import lombok.RequiredArgsConstructor;
import org.cainiaojin.domain.primary.PrimaryUser;
import org.cainiaojin.service.IUserService;
import org.cainiaojin.vo.BothUser;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户控制器
 * @author cainiaojin
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {
    private final IUserService iUserService;

    /**
     * 保存用户
     * @param bothUser
     * @return
     */
    @RequestMapping("/saveUser")
    public String saveUser(@RequestBody BothUser bothUser) {
        return iUserService.saveUser(bothUser);
    }

    /**
     * 修改用户
     * @param bothUser
     * @return
     */
    @RequestMapping("/updateUser")
    public String updateUser(@RequestBody BothUser bothUser) {
        return iUserService.updateUser(bothUser);
    }

    /**
     * 删除用户
     * @param bothUser
     * @return
     */
    @RequestMapping("/deleteUser")
    public String deleteUser(@RequestBody BothUser bothUser) {
        return iUserService.deleteUser(bothUser);
    }
    /**
     * 获取用户
     * @param bothUser
     * @return
     */
    @RequestMapping("/getUser")
    public PrimaryUser getUser(@RequestBody BothUser bothUser) {
        return iUserService.getUser(bothUser).getPrimaryUser();
    }
}
